package com.rest.demo.nio.socketdemo;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author Administrator
 * @decription
 * @Date 2018-02-09 10:18
 */
public class SocketClient {
    public static void main(String[] args) {
        SocketChannel socketChannel = null;
        try {
            socketChannel = SocketChannel.open();
            socketChannel.connect(new InetSocketAddress("127.0.0.1",81));
            ByteBuffer buffer = ByteBuffer.allocate(256);
            buffer.put("hello world".getBytes());
            buffer.flip();
            socketChannel.write(buffer);
            socketChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
